package org.song.controller;

import com.github.pagehelper.PageHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.song.exception.result.AjaxResult;
import org.song.model.dto.CommentDto;
import org.song.model.vo.Comment;
import org.song.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 博客评论控制层
 */
@Api(tags = "博客评论控制层")
@Controller
@RequestMapping(value = "/comment")
public class CommentController {

    @Autowired( required = true )
    @Qualifier( value = "commentServiceImpl")
    private CommentService commentService;

    /**
     * 查询所有的博客评论
     * @param commentDto
     * @return
     */
    @ApiOperation(value = "查询所有的博客评论" , notes = "查询所有的博客评论")
    @ResponseBody
    @RequestMapping(value = "/listComments" , method = RequestMethod.GET)
    public AjaxResult<List<Comment>> listComments(@ApiParam(value = "commentDto实例接受查询参数") @NonNull CommentDto commentDto) {
        PageHelper.startPage(commentDto.getPage() , commentDto.getSize());
       return AjaxResult.success(commentService.listComments(commentDto));
    }

    /**
     * 删除博客评论
     * @param comment
     * @return
     */
    @ApiOperation(value = "删除博客评论" , notes = "删除博客评论")
    @ResponseBody
    @RequestMapping(value = "/deleteComment" , method = RequestMethod.DELETE)
    public AjaxResult<Integer> deleteComment(@ApiParam(value = "接受需要删除的博客评论") @RequestBody @NonNull Comment comment) {
        return AjaxResult.success(commentService.deleteComment(comment));
    }

    /**
     * 增加博客评论
     * @param comment
     * @return
     */
    @ApiOperation(value = "增加博客评论" , notes = "增加博客评论")
    @ResponseBody
    @RequestMapping(value = "/insertComment" , method = RequestMethod.PUT)
    public AjaxResult<Integer> insertComment(@ApiParam(value = "博客评论") @NonNull @RequestBody Comment comment) {
        return AjaxResult.success(commentService.insertComment(comment));
    }

    /**
     * 增加博客评论
     * @param comment
     * @return
     */
    @ApiOperation(value = "更新博客评论" , notes = "更新博客评论")
    @ResponseBody
    @RequestMapping(value = "/updateComment" , method = RequestMethod.POST)
    public AjaxResult<Integer> updateComment(@ApiParam(value = "根据传入的评论信息进行博客评论更新") @NonNull @RequestBody Comment comment) {
        return AjaxResult.success(commentService.updateComment(comment));
    }


}
